package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-09-06
 * Description
 */
public class Solution23 {
    public int maxProfit(int[] prices) {
        int minCost = Integer.MAX_VALUE, maxProfit = 0;
        for (int price : prices) {
            minCost = Math.min(minCost, price); // 更新最小的值
            maxProfit = Math.max(maxProfit, price - minCost);
        }
        return maxProfit;
    }
}
